let native = {
    randomNum(len = 12) {
        return Math.floor(Math.pow(10, len) * Math.random());
    },
    call(msgName, ...params) {
        return new Promise((resolve, reject) => {
            let eventName = `${msgName}_${this.randomNum()}`;
            eventer.once(eventName, (obj) => {
                resolve(obj);
            });
            window.nativeCall(eventName, ...params);
        })
    },
    init() {
        window.nativeCall(`native_registe_callback`, (msgName, ...otherParams)=>{
            eventer.emit(msgName, ...otherParams);
        });
    },
};
native.init();

let system = {
    getMsgName(args) {
        return `system_${args}`
    },
    async getOSVersion() {
        let msgName = this.getMsgName("getOSVersion");
        let osVersion = await native.call(msgName);
        return osVersion;
    },
};

let getSystemInfoBtn = document.querySelector("#getSystemInfoBtn");
getSystemInfoBtn.addEventListener("click", async() => {
    let select = document.querySelector("#systemInfoTypeSelect")
    let val = select.selectedOptions[0].value
    let result = await system[val]();
    alert(result);
})